<template>
  <el-dialog
    class="submitPeplyFileDialog"
    title="提交答复补正文件"
    :visible.sync="isShow"
    center
    :close="shoutongClose"
  >
    <el-form
      ref="form"
      :rules="rules"
      :model="form"
      label-width="120px"
      label-position="top"
    >

      <el-form-item label="答复补正" prop="file">
        <manualUpload
          :typeLimit="['.pdf', '.zip', '.rar', '.7z']"
          :numLimit="1"
          @change="upChange"
        >
        </manualUpload>
      </el-form-item>

    </el-form>

    <span slot="footer">
      <el-button size="mini" @click="cancel">取 消</el-button>
      <el-button
        type="success"
        size="mini"
        :loading="isSendBtnLoading"
        @click="sendBtn"
        >确认上传</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import manualUpload from "~/components/manualUpload";
import axios from "axios";
export default {
  components: {
    manualUpload,
  },
  data() {
    return {
      isShow: false,
      orderdata: null,
      form: {
        file: null,
      },
     
      rules: {},
      isSendBtnLoading: false,
      baseUrl: global.baseurl,
    };
  },
  methods: {
    show(row) {
      this.isShow = true;
      this.orderdata = row;
    },
    cancel() {
      this.isShow = false;
      this.$refs["form"].resetFields();
    },
    upChange(data) {
      if (data.length) {
        this.form.file = data[0].raw;
      } else {
        this.form.file = null;
      }
    },
    fileUpChange(data) {
      if (data.length) {
        this.form.file2 = data[0].raw;
      } else {
        this.form.file2 = null;
      }
    },
    shoutongClose(data) {
      this.isShow = false;
      data = [];
    },
    sendBtn() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (!this.form.file) {
            this.$message("请上传答复补正文件！");
            return;
          }

          this.sendSubmit();
        }
      });
    },
    sendSubmit() {
      let finals = this.orderdata.id;

      let params = new FormData();
      for (let key in this.form) {
        params.append(key, this.form[key]);
      }
      this.isSendBtnLoading = true;
      axios({
        method: "post",
        url: this.baseUrl + `/api/finals/${finals}/agency/answer`,
        data: params,
        headers: {
          "Content-Type": "multipart/form-data",
          Authorization: "Bearer " + $cookies.get("token"),
        },
      }).then((res) => {
        if (res.data.code == 200) {
          this.isSendBtnLoading = false;
          this.$alert(`已发送答复补正文件`, "提示", {
            confirmButtonText: "确定",
            callback: (action) => {},
          });
          this.$emit("refresh");
          this.cancel();
        } else {
          this.isSendBtnLoading = false;
          this.$alert(res.data.message, "提示", {
            confirmButtonText: "确定",
            callback: (action) => {},
          });
        }
      });
    },
  },
};
</script>

<style lang='less'>
.submitPeplyFileDialog {
  .el-dialog {
    width: 500px;
  }
  .titleST {
    margin-bottom: 20px;
  }
  .el-select {
    width: 100%;
  }
  .tipWarp {
    margin-top: 20px;
    .tiptip {
      font-size: 12px;
    }
  }
  .sendReplyFileDialog_btn {
    text-align: center;
  }
}
</style>